<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->increments('id');
            $table->bigInteger('agent_id')->nullable();
            $table->string('openid')->index()->default('')->comment('openid');
            $table->bigInteger('video_id')->index()->comment('视频ID');
            $table->string('no')->index()->nullable()->comment('订单号');
            $table->string('transaction_id')->nullable()->comment('平台单号');
            $table->decimal('price')->comment('金额');
            $table->decimal('agent_price')->comment('代理金额');
            $table->timestamp('paid_at')->index()->nullable()->comment('支付时间');
            $table->string('appid')->nullable();
            $table->string('mch_id')->nullable();
            $table->string('type')->nullable();
            $table->string('ip')->nullable()->index();
            $table->text('ua')->nullable();
            $table->tinyInteger('is_deduct')->index()->default(0)->comment('是否扣量');
            $table->tinyInteger('valid')->index()->default('0')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
